<?php

class Ext_Avatar_Show_Adapter_Base extends Ext_Avatar_Show_Abstract
{    
    public function __construct()
    {
    }
    
    public function build($avatarId)
    {
        $avatar = App_Model_DbTable_Avatar::getInstance()->getRowById($avatarId);
        if(!$avatar){
            return "";
        }
        
        $this->big    = $this->_buildUrl($avatar['big']);
        $this->middle = $this->_buildUrl($avatar['middle']);
        $this->small  = $this->_buildUrl($avatar['small']);
        $this->thumb  = $this->_buildUrl($avatar['thumb']);
    }
    
    private function _buildUrl($imageBaseId)
    {
        if(!$imageBaseId){
            return "";
        }
        $imageBase = App_Model_DbTable_Image_Base::getInstance()->getRowById($imageBaseId);
        if(!$imageBase){
            return "";
        }
        $path     = $imageBase['path'];
        $fileName = $imageBase['fileName'];
        
        $config = Ext_Config::getInstance()->getConfig('image');
        
        $url = '';
        if(isset($config->storage->base->url)){
            $url .= rtrim($config->storage->base->url, "/");
        }
        
        $url .= "/".$path.'/'.$fileName;
        
        return $url;
    }
}
